package com.example.yls.demob;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddStuActivity extends AppCompatActivity {
    private EditText editname;
    private EditText editstuno;
    private EditText editage;
    private Button addstu;
    private EditText editsex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_stu);

               initBundler();
               addstuEvent();
    }

    private void addstuEvent() {
                  addstu.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent intent=new Intent();
                          String stuno=editstuno.getText().toString();
                          String name=editname.getText().toString();
                          int age=Integer.valueOf(editage.getText().toString());
                          String sex=editsex.getText().toString();
                          intent.putExtra("STUNO",stuno);
                          intent.putExtra("NAME",name);
                          intent.putExtra("AGE",age);
                          intent.putExtra("SEX",sex);
                          setResult(2001,intent);
                          finish();
                      }
                  });

    }

    private void initBundler() {

               editage=findViewById(R.id.edit_age);
               editname=findViewById(R.id.edit_name);
               editstuno=findViewById(R.id.edit_stuno);
               addstu=findViewById(R.id.btn_addstu2);
               editsex=findViewById(R.id.edit_sex);

    }


}
